#ifndef ARRAY_H
#define ARRAY_H

template < class T > class Array {
    static const int initial = 10;
    T *buf;
    unsigned int cap;
    unsigned int len;
public:
    Array():buf(new T[initial]), cap(initial), len(0) {
    }
    ~Array() {
        delete[]buf;
    }

    Array(const Array & A):buf(new T[A.cap]), cap(A.cap), len(A.len) {
        for (unsigned int i = 0; i < len; i++)
            buf[i] = A.buf[i];
    }

    Array & operator=(const Array & A) {
        if (this == &A)
            return *this;
        delete[]buf;
        len = A.len;
        cap = A.cap;
        buf = new T[A.cap];
        for (unsigned int i = 0; i < len; i++)
            buf[i] = A.buf[i];
        return *this;
    }

    inline T & operator[](unsigned int i) {
        return buf[i];
    }
    inline T operator[](unsigned int i) const {
        return buf[i];
    } inline int size() const {
        return len;
    } void push(const T & t) {
        if (len < cap) {
            buf[len++] = t;
            return;
        }
        cap <<= 1;
        T *tmp = new T[cap];
        for (unsigned int i = 0; i < len; i++)
            tmp[i] = buf[i];
        tmp[len++] = t;
        delete[]buf;
        buf = tmp;
    }
    inline const T & pop() {
        return buf[--len];
    }
    int contains(const T & t) {
        for (int i = 0; i < len; i++)
            if (buf[i] == t)
                return 1;
        return 0;
    }
    inline void clear() {
        len = 0;
    }
};

#endif
